<?php
	$obj=new Menu();
	if ( strcasecmp( @ $_SERVER['REQUEST_METHOD'], 'POST' ) == 0 )
	{
		
		$arr=array();
		
		/*$result=array();
		travelArray($arr,&$result);
		//print_r($arr);
		print_r($result);*/
		$data=array();
		$obj->travel("",$data);
		for($i=1;$i<count($data);$i++)
		{
			$obj->loadByKey($data[$i]);
			//echo $obj->pathNodeID()." - ";
			//print_r( $_POST['delete'.$obj->pathNodeID()]);
			$ar=$_POST['delete'.$obj->pathNodeID()];
			if(count($ar)>0)
			{
				foreach($ar as $key => $val)
				array_push($arr,$val);
			}
		} 
		$s=arrToList($arr,",");
		
		$obj->deleteList($conn,$arr);
		$pos=$_POST['Pos'];
		if(count($pos)>0)
		{
			foreach($pos as $key=>$val)
			{
				$obj->MenuID= $key;
				$obj->Pos =$val;
				$obj->updatePos($conn);
			}
			
		}
		
		//linkto("?module=$module");
	}
?>
<script language="javascript">
	arrlist =new Array()
</script>
<form name="f" action="" method="post" enctype="multipart/form-data">
<div class="ContentTitle">
    <div class="left" style="padding-top:8px"><?php echo $objModule->ModuleName?></div>
    <div class="CMSButton right">
    	<a href="#" onclick="f.submit()">Cập nhật vị trí</a>
        <?php
		if($objUserType->isAllow($objModule->ModuleID,1)!=-1)
		{
		?>
		<a href="?module=<?php echo $module?>&action=add">Thêm</a>
		<?php
		}
		?>
        <?php
        if($objUserType->isAllow($objModule->ModuleID,2)!=-1)
		{
		?>
                <a href="#" onclick="fsubmit()">Xóa</a>
		<?php
		}
		?>
    </div>    
    <div class="clear"></div>
</div>
<ul id="ContentTabs" class="shadetabs">
    <!--
    <li><a class="selected" onclick="ShowHideDiv('Tab',1,2)">General Information</a></li>
    <li><a onclick="ShowHideDiv('Tab',1,2)">Account Information</a></li>
    -->
</ul>       

<div id="Tab1" class="TabContainer" style="display:block">
<!-------------CONTENT OF EACH MODULE ---------------------------->
<table width="100%" class="list" cellpadding="0" cellspacing="0">
	<thead>
   	  <tr class="thead" height="20px" align="center">
      	  <td class="tdright" width="3%" align="center">
          <input type="checkbox" onclick="$('input[name*=\'delete\']').attr('checked', this.checked);"/>
          </td>
          <td class="tdleft" width="2%"></td>   
          <td class="tdleft" width="38%">Danh Mục</td>
          <td class="tdleft" width="38%"><!--Menu--></td>
<!--          <td class="tdleft">Parent</td>-->
 
       	  <td class="tdcenter">Tool</td>
      </tr>
    </thead>
    <tbody>
<?php
	
	$data=array();
	$obj->travel("",$data);
	for($i=1;$i<count($data);$i++)
	{
		$obj->loadByKey($data[$i]);
		$pa=new Menu();
		$pa->loadByKey($obj->MenuParent);
		$end="";
		if($obj->isLastChid()==true)
			$end="end";
		//check
		if($objUserType->UserTypeID=="supperadmin" || $objUserType->UserTypeID=="admin")
		{
?>
		<tr class="<?php echo $class?> lv<?php echo $obj->deep($obj->MenuID)?><?php echo $end?>" style="border:inset">
            <td class="tdright">
             	<input type="checkbox" name="delete<?php echo $obj->pathNodeID()?>[<?php echo $i?>]" value="<?php echo $obj->MenuID?>"
				<?php
				if(count($obj->getListChil($obj->MenuID)) >0 )
				{
				?>
				
				onclick="$('input[name*=\'delete<?php echo $obj->pathNodeID()?>\']').attr('checked', this.checked);"
				<?php
				}
				?>
				/>
            </td>
            <td class="tdleft">
				
				
            </td>            
            <td class="tdleft lv<?php echo $obj->deep($obj->MenuID)?><?php echo $end?>">
            	<input type="text" name="Pos[<?php echo $obj->MenuID?>]" value="<?php echo $obj->Pos?>" style="width:15px"/>
					<?php echo $obj->MenuName?>
<?php
		if( $obj->ModuleID=="post")
		{
			
?>
				<a class="buttonlink" onclick="closeAll(); display('view<?php echo $obj->MenuID?>'); ajaxpage('modules/post/postajax.php?type=<?php echo $obj->MenuID?>', 'view<?php echo $obj->MenuID?>')"><?php echo $obj->getType()?></a>
				<div id="view<?php echo $obj->MenuID?>" class="viewobject" style="position:absolute;margin-left:200px;margin-top:-15px;display:none"></div>
				<script language="javascript">
					arrlist.push("view<?php echo $obj->MenuID?>")
				</script>
<?php
			
			
		}
		if($obj->ModuleID=="wallpaper")
		{
?>
				<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>"><?php echo $obj->getType()?></a>
<?php
		}
		if($obj->ModuleID=="videoclip")
		{
?>
				<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>"><?php echo $obj->getType()?></a>
<?php
		}
		if($obj->ModuleID=="product")
		{
?>
				<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>"><?php echo $obj->getType()?></a>
<?php
		}
?>
				
			</td>
            <td></td>

            
            
          	<td class="tdleft linkcontrol">
<?php
		if($objUserType->isAllow($objModule->ModuleID,3)!=-1)
		{
?>
            	[<a class="buttonlink" href="?module=<?php echo $module?>&action=get&id=<?php echo $obj->MenuID?>">Cài đặt</a>]
<?php
		}
?>
<?php
		if($objUserType->isAllow($objModule->ModuleID,3)!=-1)
		{
			switch($obj->ModuleID)
			{
				case "content":
?>
            	[<a class="buttonlink" href="?module=<?php echo $module?>&action=edit&id=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php
				
					break;
				case "post":
?>
				[<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				
				case "link":
?>
				[<a class="buttonlink" href="?module=<?php echo $module?>&action=editlink&id=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "rss":
?>
				[<a class="buttonlink" href="?module=<?php echo $module?>&action=editrss&id=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "contact":
?>
				[<a class="buttonlink" href="?module=<?php echo $module?>&action=editcontact&id=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "product":
?>
				[<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				
				case "banner":
?>
				[<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
			}
		}
?>
<?php
		if($objUserType->isAllow($objModule->ModuleID,1)!=-1 /*&& $obj->deep($obj->MenuID)==0*/)
		{
?>
				[<a class="buttonlink" href="?module=<?php echo $module?>&action=add&parent=<?php echo $obj->MenuID?>">Thêm menu con</a>]
<?php
		}
?>

            </td>
        </tr>
<?php
		}
		else
			if($objUserType->isPermission($obj->ModuleID)!=-1)
			{
?>

    	<tr class="<?php echo $class?> lv<?php echo $obj->deep($obj->MenuID)?><?php echo $end?>">
            <td class="tdright">
             	<input type="checkbox" name="delete<?php echo $obj->pathNodeID()?>[<?php echo $i?>]" value="<?php echo $obj->MenuID?>"
				<?php
				if(count($obj->getListChil($obj->MenuID)) >0 )
				{
				?>
				
				onclick="$('input[name*=\'delete<?php echo $obj->pathNodeID()?>\']').attr('checked', this.checked);"
				<?php
				}
				?>
				/>
            </td>
            <td class="tdleft">
				
				
            </td>            
            <td class="tdleft">
            	<input type="text" name="Pos[<?php echo $obj->MenuID?>]" value="<?php echo $obj->Pos?>" style="width:15px"/>
					<?php echo $obj->MenuName?> 
<?php
		if($obj->ModuleID=="rss" || $obj->ModuleID=="post")
		{
			//if($obj->Param=="")
			{
?>
				<a class="buttonlink" onclick="closeAll(); display('view<?php echo $obj->MenuID?>'); ajaxpage('modules/post/postajax.php?type=<?php echo $obj->MenuID?>', 'view<?php echo $obj->MenuID?>')"><?php echo $obj->getType()?></a>
				<div id="view<?php echo $obj->MenuID?>" class="viewobject" style="position:absolute;margin-left:200px;margin-top:-15px;display:none"></div>
				<script language="javascript">
					arrlist.push("view<?php echo $obj->MenuID?>")
				</script>
<?php
			}
		}
		if($obj->ModuleID=="wallpaper")
		{
?>
				<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>"><?php echo $obj->getType()?></a>
<?php
		}
		if($obj->ModuleID=="product")
		{
?>
				<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>"><?php echo $obj->getType()?></a>
<?php
		}
?>
				
			</td>
            <td></td>

            
            
          	<td class="tdleft linkcontrol">

<?php
		if($objUserType->isAllow($objModule->ModuleID,3)!=-1)
		{
			switch($obj->ModuleID)
			{
				case "":
?>
            	[<a class="buttonlink" href="?module=<?php echo $module?>&action=edit&id=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php
				
					break;
				case "post":
?>
				[<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "wallpaper":
?>
				[<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "link":
?>
				[<a class="buttonlink" href="?module=<?php echo $module?>&action=editlink&id=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "rss":
?>
				[<a class="buttonlink" href="?module=<?php echo $module?>&action=editrss&id=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "contact":
?>
				[<a class="buttonlink" href="?module=<?php echo $module?>&action=editcontact&id=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "product":
?>
				[<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "download":
?>
				[<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
				case "logo":
?>
				[<a class="buttonlink" href="?module=<?php echo $obj->ModuleID?>&type=<?php echo $obj->MenuID?>">Chỉnh sửa</a>]
<?php

					break;
			}
		}
?>
<?php
		if($objUserType->isAllow($objModule->ModuleID,1)!=-1 && $obj->deep($obj->MenuID)==0)
		{
?>
				[<a class="buttonlink" href="?module=<?php echo $module?>&action=add&parent=<?php echo $obj->MenuID?>">Thêm menu con</a>]
<?php
		}
?>

            </td>
        </tr>
<?php
			}
	}
?>
    </tbody>
</table>
<!-------------END CONTENT OF EACH MODULE ---------------------------->
</div>
</form>
<script language="javascript">
from=document.f
function fsubmit()
{
	anser=confirm('Are you sure delete !')
	if(anser==true)
	{
		from.submit()
	}
}
function closeAll()
{
	for(i=0;i<arrlist.length;i++)
	{
		document.getElementById(arrlist[i]).innerHTML=''
		hidden(arrlist[i])
	}
}

</script>